package com.zsc.roadsys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsc.roadsys.entity.User;
import com.zsc.roadsys.entity.UserRole;
import com.zsc.roadsys.mapper.UserRoleMapper;
import com.zsc.roadsys.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author haoran
 */

@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {
    @Autowired
    UserRoleMapper userRoleMapper;

    @Override
    public Long getUrByUserId(Long userId) {
        QueryWrapper<UserRole> userWrapper = new QueryWrapper<>();
        userWrapper.eq("user_id", userId);
        UserRole ur = userRoleMapper.selectOne(userWrapper);
        return ur.getId();
    }

    @Override
    public boolean deleteRoleByUserId(Long id) {
        QueryWrapper<UserRole> urWrapper = new QueryWrapper<>();
        urWrapper.eq("user_id", id);
        return baseMapper.delete(urWrapper) != 0;
    }
}
